package ao

import (
	"context"
	pb "gitee.com/micro-services/protocol/room/server"
	"micro.room.server/impl"
)

type RoomController struct{}

func (rc *RoomController) CreateRoom(ctx context.Context, r *pb.CreateRoomReq, w *pb.CreateRoomRsp) error {
	rsp, err := impl.CreateRoom(ctx, r)
	if err != nil {
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg
	return nil
}

func (rc *RoomController) UpdateRoom(ctx context.Context, r *pb.UpdateRoomReq, w *pb.UpdateRoomRsp) error {
	rsp, err := impl.UpdateRoom(ctx, r)
	if err != nil {
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg
	return nil
}

func (rc *RoomController) DeleteRoom(ctx context.Context, r *pb.DeleteRoomReq, w *pb.DeleteRoomRsp) error {
	rsp, err := impl.DeleteRoom(ctx, r)
	if err != nil {
		return err
	}

	w.RetCode = rsp.RetCode
	w.Msg = rsp.Msg
	return nil
}

func (rc *RoomController) BatchRoomInfo(ctx context.Context, r *pb.BatchRoomInfoReq, w *pb.BatchRoomInfoRsp) error {
	info, err := impl.BatchRoomInfo(ctx, r)
	if err != nil {
		return err
	}

	w.Info = info
	return nil
}

func (rc *RoomController) SearchRoom(ctx context.Context, r *pb.SearchRoomReq, w *pb.SearchRoomRsp) error {
	info, count, err := impl.SearchRoom(ctx, r)
	if err != nil {
		return err
	}

	w.List = info
	w.Count = count
	return nil
}
